#include<bits/stdc++.h>
using namespace std;
const int N=2e5+5;
int t,n,ch;
char a[N];
int main()
{
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    int i,j,sum=0;
    cin>>t;
    while(t--)
    {
        sum=0;
        cin>>n;
        for(i=1;i<=n;i++)   cin>>a[i];
        for(i=1;i<=n;i++)
        {
            for(j=i+2;j<=n;j++)
                if(a[j]==a[i])
                {
                    sum+=a[i]-'0';
                    break;
                }
        }
        cout<<sum<<endl;
    }
    fclose(stdin);
    fclose(stdout);
    return 0;
}
